from urllib import request,parse
from json import loads
while True:
    ctrl_num = input(r'''
您希望干嘛？（输入数字）
1.视频信息   2.用户数据
按 CTRL+C 结束
''')
    if ctrl_num == '1':
        video_num = input('''
请输入视频号
记得带上av或BV前缀
''')
        if video_num[:2] == 'av' or video_num[:2] == 'AV':flag = False
        elif video_num[:2] == 'BV' or video_num[:2] == 'bv':flag = True
        else:continue
        URL = r'http://api.bilibili.com/x/web-interface/archive/stat?'
        if flag:URL += r'bvid='
        else:URL += r'aid='
        URL += video_num[2:]
        req = request.Request(URL)
        req.add_header("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36(KHTML, like Gecko) Chrome/50.0.2661.87 Safari/537.36")
        with request.urlopen(req) as f:
            temp1 = f.read()
            temp1 = loads(temp1)
            if temp1['code'] != 0:
                print('获取失败！错误代码：',temp1['code'],'错误值：',temp1['message'])
                continue
            print('\n' r'[INFO]获取成功！')
            temp2 = temp1['data']
            print('av号：',temp2['aid'])
            print('bv号：',temp2['bvid'])
            print('投币数：',temp2['coin'])
            print('共被浏览过',temp2['view'],'次')
            print('共有',temp2['reply'],'个评论')
            print('点赞数：',temp2['like'])
            print('收藏数：',temp2['favorite'])
            print('分享数：',temp2['share'])
            print(r'授权方式(1代表原创，2代表搬运):',temp2['copyright'])
            print(r'历史排名：',temp2['his_rank'])
            baipiao = temp2['view'] - temp2['coin'] - temp2['like'] - temp2['favorite']
            print(r'至少有',baipiao,r'人白嫖')
            print(r'白嫖率：',baipiao / temp2['view']*100,r'%')
    elif ctrl_num == '2':
        uid = input('''
请输入UID
一定要是纯数字！
''')
        checker = [str(x) for x in range(10)]
        for i in uid:
            if i not in checker:
                print('请检查格式！')
                exit_flag = True
                break
        else:exit_flag = False
        del checker
        if exit_flag:continue
        del exit_flag
        URL = 'https://api.bilibili.com/x/relation/stat?vmid=' + uid
        req = request.Request(URL)
        req.add_header("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36(KHTML, like Gecko) Chrome/50.0.2661.87 Safari/537.36")
        with request.urlopen(req) as f:
            temp1 = f.read()
            temp1 = loads(temp1)
            if temp1['code'] != 0:
                print('获取失败！错误代码：',temp1['code'],'错误值：',temp1['message'])
                continue
            print('\n',r'[INFO]API-01获取成功！')
            temp2 = temp1['data']
            print('TA一共关注了',temp2['following'],'人')
            print('TA现在',('有' if temp2['black'] else '没有'),'被关进小黑屋')
            print('TA现在有',temp2['follower'],'名粉丝')
            print(r'TA的铃声(我也不知道啥意思)(whisper)',temp2['whisper'])
            print('他的MID',temp2['mid'])